home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / usefull / abook-install / arexx / abook.amirx next >
Encoding:
Text File  |  1995-12-30  |  5.5 KB  |  195 lines

  1. /*
  2. **  $VER: ABook.AMIRX V00.01 (30.12.95)
  3. **
  4. **  © 1995 Joerg Krause
  5. **
  6. **  $PROGRAMNAME:
  7. **    ABook.AMIRX
  8. **
  9. **  FUNCTION:
  10. **    Script for Address-Book and AmIRC V0.77 and higher.
  11. **
  12. **    Parses the /whois command and add the realname and the E-Mail to
  13. **    Address-Book's database.
  14. **
  15. **    Put this script in PROGDIR:rexx/ and add this as an alias with the
  16. **    command:  "/alias ABOOK /rx ABook %p"
  17. **
  18. **  $HISTORY:
  19. **
  20. **   30.12.95 : V00.01 :  initial release
  21. **
  22. **
  23. */
  24.  
  25.  
  26. OPTIONS RESULTS
  27. SIGNAL ON SYNTAX
  28.  
  29. if ~show('P','ABOOK_SERVER') then do
  30.   exit 10
  31. end
  32.  
  33. parse arg nick
  34.  
  35. /* send the /whois command */
  36. if nick ~="" then do
  37.   'SAY "/WHOIS "'||nick
  38.   found = 0
  39.   do until found =1
  40.     'GETLINE'
  41.     sep=pos(' ', LINE.REST)
  42.     if sep ~= 0 then
  43.       do
  44.         Nickname=left(LINE.REST, sep)
  45.         if Nickname =nick then do
  46.           found=1
  47.         end
  48.       end
  49.   end
  50.   /* Seems to be the /whois line */
  51.   /* Now seperate the contents   */
  52.   sep1   = pos(' ',LINE.REST,sep+1)
  53.   Email1 = substr(LINE.REST,sep+1,sep1-(sep+1))
  54.   sep2   = pos(' ',LINE.REST,sep1+1)
  55.   Email2 = substr(LINE.REST,sep1+1,sep2-(sep1+1))
  56.   eaddr  = EMAIL1||'@'||EMAIL2
  57.   sep3   = lastpos(':',LINE.REST)
  58.   Name   = substr(LINE.REST,sep3+1)
  59.  
  60.   /* parse given args */
  61.   sep=lastpos(' ', Name)
  62.   if sep = 0 then
  63.     do
  64.     prename = ''
  65.     surname = Name
  66.     end
  67.   else
  68.     do
  69.       prename = left(Name, sep-1)
  70.       surname = substr(Name, sep+1)
  71.     end
  72.     incomment = ''
  73.     /* search for an existing entry */
  74.     address 'ABOOK_SERVER'
  75.     'SEARCH '||eaddr||' NOCASE EMAIL STEM=ABDATA.'
  76.     if RC = 0 then
  77.       do
  78.         if ABDATA.COUNT > 0 then
  79.           do
  80.             'REQUESTRESPONSE TITLE="ABook Import" BUTTON="**_OK"',
  81.                   ' PROMPT="There is allready an entry with email-address\n\33c\338'||eaddr||'\330\nin the database !"'
  82.  
  83.             signal done
  84.           end
  85.       end
  86.     lock = -1
  87.     'SEARCH '||surname||' NOCASE LAST STEM=ABDATA.'
  88.     if RC=0 then
  89.       do
  90.         if ABDATA.COUNT > 0 then
  91.           do
  92.             if ABDATA.COUNT > 1 then
  93.               do
  94.                 if prename <> '' then
  95.                   do
  96.                     /* hmpf, multiple occurences... */
  97.                     'SEARCH ||'prename'|| NOCASE FIRST STEM=ABMULT.'
  98.                     if RC=0 then
  99.                       do
  100.                         if ABDATA.COUNT > 0 then
  101.                           do
  102.                             if ABDATA.COUNT > 1 then
  103.                               do
  104.                                 'REQUESTRESPONSE TITLE="ABook Import" BUTTON="**_OK"',
  105.                                       'PROMPT="Sorry, too many matching entries\nin database. Couldn''t add !"'
  106.  
  107.                                 signal done
  108.                               end
  109.                             else
  110.                               do
  111.                                 entry = 1
  112.                                 lock = 0
  113.                                 do while ABMULT.1 <> ABDATA.entry
  114.                                   entry = entry + 1
  115.                                   if entry > ABDATA.COUNT then
  116.                                     do
  117.                                       /* hm, no matching entry ? Maybe prename is an abbrev, but who cares :-) */
  118.                                       lock = -1
  119.                                       leave
  120.                                     end
  121.                                 end
  122.                                 if lock <> -1 then
  123.                                   lock = ABDATA.entry
  124.                               end
  125.                           end
  126.                       end  /* found matching entry via pre- & surname */
  127.                   end
  128.                 else
  129.                   do
  130.                     'REQUESTRESPONSE TITLE="ABook Import" BUTTON="**_OK"',
  131.                           'PROMPT="Sorry, too many matching entries\nin database. Couldn''t add !"'
  132.  
  133.                     signal done
  134.                   end
  135.               end
  136.             else
  137.               do
  138.                 /* one matching entry, append email and comment */
  139.                 lock = ABDATA.1
  140.               end
  141.           end /* search for lock */
  142.         if lock == -1 then
  143.           do
  144.             /* add */
  145.             drop ADDR.
  146.             ADDR.LAST = surname
  147.             ADDR.FIRST = prename
  148.             ADDR.EMAIL.COUNT = 1
  149.             ADDR.EMAIL.1.ADR = eaddr
  150.             ADDR.EMAIL.1.DES = incomment
  151.             'REQUESTRESPONSE TITLE="ABook Import" BUTTON="**_Add|_Cancel"',
  152.                   'PROMPT="Add entry\nName : \338'||ADDR.FIRST||' '||ADDR.LAST||'\330\nEmail : \338',
  153.                   ||eaddr||' '||incomment||'\330\nto the database ?"'
  154.  
  155.             if RC = 0 then
  156.               if RESULT = 1 then
  157.                 do
  158.                   'ADD STEM=ADDR.'
  159.                   'SAVE'
  160.                 end
  161.             signal done
  162.           end
  163.         else
  164.           do
  165.             /* append */
  166.             drop ADDR.
  167.             'LOCK '||lock
  168.             'QUERY STEM=ADDR.'
  169.             emailno = ADDR.EMAIL.COUNT + 1
  170.             ADDR.EMAIL.COUNT = emailno
  171.             ADDR.EMAIL.emailno.ADR = eaddr
  172.             ADDR.EMAIL.emailno.DES = incomment
  173.             'REQUESTRESPONSE TITLE="ABook Import" BUTTON="**_Append|_Cancel"',
  174.                   'PROMPT="Append to entry\nName : \338'||ADDR.FIRST||' '||ADDR.LAST||'\330\nEmail : \338',
  175.                   ||eaddr||' '||incomment||'\330\nto the database ?"'
  176.  
  177.             if RC = 0 then
  178.               if RESULT = 1 then
  179.               do
  180.                 'EDIT STEM=ADDR.'
  181.                 'SAVE'
  182.               end
  183.             'UNLOCK '||lock
  184.           end
  185.       end
  186. end
  187.  
  188.  
  189. done:
  190. exit
  191.  
  192. SYNTAX:
  193. exit 20
  194.  
  195.